package com.six.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.ljw.util.DBManager;
import com.ljw.util.QueryDataResult;
import com.six.entity.Imgs;


public class ImgsDaoImpI {
	/**
	 * 全查
	 * @return
	 */
	public ArrayList<Imgs> getImagesList(int id){
		String sql="select * from imgs where productid="+id;
		System.out.println("执行的sql语句是"+sql);
		QueryDataResult executeQuery = DBManager.executeQuery(sql);
		ArrayList<Imgs> list=new ArrayList<Imgs>();
		if (executeQuery!=null) {
			ResultSet rs=executeQuery.rs;
			try {
				while (rs.next()) {
					Imgs i=new Imgs(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4));
					list.add(i);	
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				executeQuery.close();
			}
		}

		System.out.println(list);
		return list;
	}
	
	/**
	 * 单查
	 * @param id
	 * @return
	 */
	public Imgs getimagesById(int id){
		String sql="select * from imgs where id="+id;
		System.out.println("执行的sql语句是"+sql);
		QueryDataResult executeQuery = DBManager.executeQuery(sql);
		
		if (executeQuery!=null) {
			ResultSet rs=executeQuery.rs;
			try {
				while (rs.next()) {
					Imgs i=new Imgs(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4));
					return i;
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}finally {
				executeQuery.close();
			}
		}
		return null;
		
	}
	
}
